package com.controller.Hua;

import com.pojo.Hua.*;
import com.service.Hua.IMaterialWarehouseOutService;
import com.service.Hua.IMaterialWarehousePDService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("huaPDWarehouse/")
public class MaterialWarehousePDController {
    @Autowired
    IMaterialWarehousePDService iMaterialWarehousePDService;

    @GetMapping("getPDMaterial")
    public List<HuaMaterial> getMaterial() {
        List<HuaMaterial> pdServiceMaterials = iMaterialWarehousePDService.getMaterials();
        return pdServiceMaterials;
    }

    @GetMapping("getPDMaterialWarehouse")
    public List<HuaMaterialWarehouse> getMaterialWarehousePD(Long materialId) {
        List<HuaMaterialWarehouse> pdServiceMaterialWarehouses = iMaterialWarehousePDService.getBach(materialId);
        return pdServiceMaterialWarehouses;
    }

    @GetMapping("getMaterialDetailPd")
    public List<HuaMaterialWarehousePdView> getMaterialDetailPd(Long materialCode) {
        List<HuaMaterialWarehousePdView> materialWarehousePd = iMaterialWarehousePDService.getMaterialWarehousePd(materialCode);
        return materialWarehousePd;
    }

    @PostMapping("addWarehousePD")
    public Res addWarehousePD(@RequestBody Receipts receipts) {
        Res res = new Res();
        int i = iMaterialWarehousePDService.addPdRecord(receipts);
        if (i>0){
            res.setCode(200);
            res.setMsg("添加盘点信息成功");
        }else{
            res.setCode(400);
            res.setMsg("盘点失败");
        }
        return res;
    }

    @GetMapping("getReceipts")
    public List<Receipts> getReceipts() {
        List<Receipts> receipts = iMaterialWarehousePDService.getReceipts();
        return receipts;
    }
}
